package com.example.helloworld.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;

import com.example.helloworld.adapter.IconTextListAdapter;
import com.example.helloworld.adapter.OnDataSelectionListener;

public class DataListView extends ListView {

	private IconTextListAdapter adapter;
	private OnDataSelectionListener selectionListener;
	
	public DataListView(Context context) {
		super(context);
		
		init();
	}
	
	public DataListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		
		init();
	}
	
	public void init() {
		//setOnItemClickListener(new OnItemClickAdapter());
		setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				if (selectionListener == null) {
					return;
				}
				
				selectionListener.onDataSelected(arg0, arg1, arg2, arg3);
			}
		});
		
	}
	
	public void setAdapter(BaseAdapter adapter) {
		super.setAdapter(adapter);
	}
	
	@Override
	public BaseAdapter getAdapter() {
		return (BaseAdapter)super.getAdapter();
	}

	public void setOnDataSelectionListener(OnDataSelectionListener listener) {
		this.selectionListener =	listener;
	}
	
	public OnDataSelectionListener getOnDataSelectionListener() {
		return selectionListener;
	}
	
	/*
	class OnItemClickAdapter implements OnItemClickListener {
		public OnItemClickAdapter() {}
		
		@Override
		public void onItemClick(AdapterView parent, View v, int position, long id) {
			if (selectionListener == null) {
				return;
			}
			
			selectionListener.onDataSelected(parent, v, position, id);
		}
	}
	*/
}
